package com.terren.webdig.setting.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.terren.webdig.basic.impl.BasicServiceSupportImpl;
import com.terren.webdig.setting.entity.LoginUser;
import com.terren.webdig.setting.service.IUserLoginService;

@Service("userLoginService")
public class UserLoginServiceImpl extends BasicServiceSupportImpl implements IUserLoginService {
	private final String SQL_MAPPER = "setting.userLoginMapper";

	/**
	 * 用户登录
	 * 
	 * @param loginUser
	 * @return
	 */
	public LoginUser userLogin(LoginUser loginUser) throws Exception {
		LoginUser dbUser = (LoginUser) basicDao.findForObject(SQL_MAPPER + ".userLogin", loginUser);
		return dbUser;
	}
	/**
	 * 用户名是否存在
	 * 
	 * @throws Exception
	 */
	@Override
	public boolean validateUserName(LoginUser param) throws Exception {

		LoginUser dbUser = (LoginUser) basicDao.findForObject(SQL_MAPPER + ".validataUserName", param);
		if (dbUser == null) {
			return false;// 该用户不存在
		}
		return true;// 用户存在
	}

	/**
	 * 通过用户名查询user
	 * 
	 * @throws Exception
	 */
	@Override
	public LoginUser getUserByName(LoginUser param) throws Exception {
		LoginUser dbUser = (LoginUser) basicDao.findForObject(SQL_MAPPER + ".validataUserName", param);
		return dbUser;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<LoginUser> getUserId(LoginUser loginUser) throws Exception {
		return (List<LoginUser>) basicDao.findForList(SQL_MAPPER + ".getUserId", loginUser);
	}

}
